import { toLocaleStringWithUnit, formatterCurrencyStr } from "@/utils/format";

export default {
    showTotal,
    showTotal2
}
async function showTotal(api, setFun, name, isCess) {
    try {
        let res = await api();
        if (res.msg == 'ok') {
            setFun(total => {
                let num = res.data;
                if (isCess) {
                    num = formatterCurrencyStr(num);
                } else {
                    num = toLocaleStringWithUnit(num);
                }
                total[name] = num;
                // console.log({ total });
                return total;
            });
        }
    } catch (e) {
        console.error(e);
    }
}
async function showTotal2(api, setFun, name, isCess) {
    try {
        let res = await api();
        if (res.msg == 'ok') {
            setFun(total => {
                let num = res.data;
                let full = parseFloat(res.data);
                if (isCess) {
                    num = formatterCurrencyStr(num);
                    full = full / 1e18;
                } else {
                    num = toLocaleStringWithUnit(num);
                }
                let fullStr = full.toLocaleString("zh", { style: "decimal", maximumFractionDigits: 18 });
                total[name] = {
                    num, full, fullStr
                };
                // console.log({ total });
                return total;
            });
        }
    } catch (e) {
        console.error(e);
    }
}
